import { createStore } from 'vuex'

// Moldule
import userInfo from './userInfo'
import websocket from './websocket'

export default createStore({
  state: {
    num: 0
  },
  getters: {
    getNum(state): number {
      return state.num
    }
  },
  mutations: {
    addNum(state): void {
      state.num++
    },
    addNumWithNum(state, num: number): void {
      state.num += num
    }
  },
  //异步更改 可以返回promise
  actions: {
    addNum(context) {
      context.commit('addNum')
    },
    addNumWithNum(context, num: number) {
      return new Promise(() => {
        context.commit('addNumWithNum', num)
      })
    }
  },
  modules: {
    userInfo,
    websocket
  }
})
